import java.util.*;

public class Test {
    public static void main(String[] args) {
        ArrayList<Integer> arrayList1 = new ArrayList<>();
        arrayList1.add(1);
        arrayList1.add(2);
        arrayList1.add(3);
        arrayList1.add(4);
        arrayList1.add(5);
        int size = arrayList1.size();
        for (int i = 0; i < size; i++) {
            System.out.print(arrayList1.get(i)+" ");
        }
        System.out.println();
        // :左边是ArrayList里面的元素，右边是指遍历的是谁。
        for (int x : arrayList1) {
            System.out.print(x+" ");
        }
        System.out.println();
        for (Integer x : arrayList1) {
            System.out.print(x+" ");
        }
        System.out.println();

        Iterator<Integer> it =  arrayList1.iterator();
        //it.hasNext()判断有没有下一个数据，有就打印它。
        //it.next()是访问下一个的同时，it往后走一步。
        while (it.hasNext()) {
            System.out.print(it.next()+" ");
        }
        System.out.println();
        System.out.println("===============");//大家可以自己用一下remove方法
        Iterator<Integer> it3 =  arrayList1.listIterator();
        while (it3.hasNext()) {
            System.out.print(it3.next()+" ");
        }
        ListIterator<Integer> it2 =  arrayList1.listIterator();
        while (it2.hasNext()) {
            System.out.print(it2.next()+" ");
        }
    }
    public static void main2(String[] args) {
        ArrayList<Integer> arrayList1 = new ArrayList<>();
        arrayList1.add(1);
        arrayList1.add(2);
        arrayList1.add(3);
        arrayList1.add(4);
        arrayList1.add(5);
        List<Integer> list = arrayList1.subList(1,3);
        System.out.println(list);//2,3
        System.out.println("======================");
        list.set(0,99);
        System.out.println(arrayList1);//1,99,3,4,5
        System.out.println(list);//99,3
        arrayList1.add(0,7);
        System.out.println(arrayList1);
        arrayList1.remove(new Integer(7));
        arrayList1.clear();

        System.out.println(arrayList1);

    }
    public static void main1(String[] args) {
        ArrayList<Integer> arrayList1 = new ArrayList<>();
        arrayList1.add(1);
        arrayList1.add(2);
        System.out.println(arrayList1);
        ArrayList<Integer> arrayList2 = new ArrayList<>(12);
        arrayList2.add(2);
        arrayList2.add(3);
        arrayList2.add(4);
        System.out.println(arrayList2);
        LinkedList<Integer> arrayList4 = new LinkedList<>();
        ArrayList<Integer> arrayList3 = new ArrayList<>(arrayList4);
    }
}
